<template>
  <div>
    <task-clear-list
      ref="shiftListRef"
      :task-type="taskType"
      :format-column="formatTaskListColumn"
      @on-shift-edit="handleShiftEditOpen"
      @on-record-list="handleShiftListOpen"
    />
    <task-clear-update
      ref="shiftUpdateRef"
      :format-form-render="formatTaskFormRender"
      :check-form-data="checkFormData"
      :task-type="taskType"
      :on-submit="handleShiftSubmit"
    />

    <task-clear-time-list
      ref="recordListRef"
      :task-type="taskType"
      :format-column="formatTimeListColumn"
      @on-record-edit="handleRecordEditOpen"
    />

    <task-clear-time-update
      ref="recordUpdateRef"
      :task-type="taskType"
      :format-form-render="formatTimeFormRender"
      :on-submit="handleRecordSubmit"
    />
  </div>
</template>

<script>

import TaskClearList from './task_component/list'
import TaskClearUpdate from './task_component/update'

import TaskClearTimeList from './task_time_component/list'
import TaskClearTimeUpdate from './task_time_component/update'

export default {
  name: 'TaskController',
  components: { TaskClearList, TaskClearUpdate, TaskClearTimeList, TaskClearTimeUpdate },
  props: {
    taskType: {
      type: Number,
      default: 0
    },
    formatTaskListColumn: {
      type: Function,
      default: _ => Promise.resolve(_)
    },
    formatTaskFormRender: {
      type: Function,
      default: _ => Promise.resolve(_)
    },
    formatTimeListColumn: {
      type: Function,
      default: _ => Promise.resolve(_)
    },
    formatTimeFormRender: {
      type: Function,
      default: _ => Promise.resolve(_)
    },
    checkFormData: {
      type: Function,
      default: _ => true
    }
  },

  methods: {
    handleShiftEditOpen(recordId) { // 监听任务列表 新增和修改 事件
      this.$refs.shiftUpdateRef.open(recordId)
    },
    handleShiftListOpen(recordId) { // 监听任务列表 打开 时段配置
      this.$refs.recordListRef.open(recordId)
    },
    handleShiftSubmit() { // 监听 任务配置 提交完成
      this.$refs.shiftListRef.postAttendanceList()
    },

    handleRecordEditOpen(shiftId, record) { // 监听时段列表 新增 和修改 事件
      this.$refs.recordUpdateRef.open(shiftId, record)
    },
    handleRecordSubmit() { // 监听时段 提交完成
      this.$refs.recordListRef.postAttendanceRecordList()
    }
  }
}
</script>
